package lendingbooks.activities;

import android.app.TabActivity;
import android.content.Context;
import android.content.Intent;
import android.net.ConnectivityManager;
import android.net.NetworkInfo;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.ImageView;
import android.widget.TabHost;
import android.widget.TabHost.TabSpec;
import android.widget.TextView;

public class LendingbooksActivity extends TabActivity {
	TabHost tabHost;

	private void setupTabHost() {
		tabHost = (TabHost) findViewById(android.R.id.tabhost);
		tabHost.setup();
	}

	@Override
	public void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.main);
		
		setupTabHost();
		tabHost.getTabWidget().setDividerDrawable(R.drawable.tab_divider);
		Intent searchIntent = new Intent(this, SearchBookActivity.class);
		Intent myLibraryIntent = new Intent(this, MyLibraryActivity.class);
		Intent myFriendsLibraryIntent = new Intent(this, MyFriendsLibraryActivity.class);
		
		setupTab(new TextView(this), "Search", searchIntent);
		setupTab(new TextView(this), "My library", myLibraryIntent);
		setupTab(new TextView(this), "Friends", myFriendsLibraryIntent);
		
		tabHost.getTabWidget().getChildTabViewAt(1).setVisibility(View.GONE);
		tabHost.getTabWidget().getChildTabViewAt(2).setVisibility(View.GONE);
		((LendingBooksApplication) getApplication()).setTabHost(tabHost);
	
		SearchBookActivity searchBookActivity = (SearchBookActivity) this.getCurrentActivity();
		searchBookActivity.checkFacebookLogin();	
	}

	private void setupTab(final View view, final String tag, Intent p_intent) {
		View tabview = createTabView(tabHost.getContext(), tag);
		TabSpec setContent = tabHost.newTabSpec(tag).setIndicator(tabview).setContent(p_intent);
		tabHost.addTab(setContent);

	}

	private static View createTabView(final Context context, final String text) {
		View view = LayoutInflater.from(context).inflate(R.layout.tabs_bg, null);
		TextView tv = (TextView) view.findViewById(R.id.tabsText);
		tv.setText(text);
		return view;
	}
	
	

}